package com.qijian.maindata.domain.enums;

import com.qijian.common.exception.ServiceException;
import com.qijian.common.utils.ObjectUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

public class NcOrderEnum {

    @AllArgsConstructor
    @Getter
    public enum CutType {
        FIRE("1", "火焰切割"),
        PLASMA("2", "等离子切割"),
        LASER("3", "激光切割"),
        FIBER("4", "光纤切割"),
        WATER("5", "水切割"),
        HAND("6", "手工下料"),
        Other("7", "其他下料");
        private String code;
        private Object value;

        private static Map<Object, CutType> enmuMap = new HashMap();

        //初始化map
        static {
            for (CutType item : values()) {
                enmuMap.put(item.getValue(), item);
            }
        }

        public static String getCodeByValue(Object value) {
            if (ObjectUtils.isNull(enmuMap.get(value))) {
                throw new ServiceException("E01:无匹配切割方式！");
            }
            return enmuMap.get(value).getCode();
        }
    }

    @AllArgsConstructor
    @Getter
    public enum Material {
        STEEL_PLATE("1", "钢板"),
        ALUMINIUM_PLATE("2", "铝"),
        STAINLESS_PLATE("3", "不锈");
        private String code;
        private Object value;
        private static Map<Object, Material> enmuMap = new HashMap();

        //初始化map
        static {
            for (Material item : values()) {
                enmuMap.put(item.getValue(), item);
            }
        }

        public static String getCodeByValue(Object value) {
            if (ObjectUtils.isNull(value)) {
                throw new ServiceException("E01:无使用物料，无法计算价格！");
            }
            if (String.valueOf(value).contains(String.valueOf(STAINLESS_PLATE.getValue())))
                return STAINLESS_PLATE.getCode();
            else if (String.valueOf(value).contains(String.valueOf(ALUMINIUM_PLATE.getValue())))
                return ALUMINIUM_PLATE.getCode();
            else return STEEL_PLATE.getCode();
//            if (!ALUMINIUM_PLATE.getValue().toString().contains(value.toString()))
//                return STEEL_PLATE.getCode();
//            return enmuMap.get(value).getCode();
        }
    }

}
